<?php
/**
 * 代码原链接：	https://mp.weixin.qq.com/s?__biz=MzIxODQyNTU1MA==&amp;mid=2247484133&amp;idx=1&amp;sn=9d098517a4d7fc913d3657a706e23dbd&amp;chksm=97ebf344a09c7a5277707e75ecc1a4be743d23fc22ce2b038079acd3cbc6f2af4b8fa211e503&amp;scene=27&key=&ascene=1&uin=&devicetype=iMac+MacBookPro15%2C2+OSX+OSX+12.2.1+build(21D62)&version=13080712&nettype=WIFI&lang=zh_CN&countrycode=CN&fontScale=100
 */

interface Strategy{
    function AlgorithmInterface();
}

class ConcreteStrategyA implements Strategy{
    function AlgorithmInterface(){
        echo "算法A";
    }
}

class ConcreteStrategyB implements Strategy{
    function AlgorithmInterface(){
        echo "算法B";
    }
}

class ConcreteStrategyC implements Strategy{
    function AlgorithmInterface(){
        echo "算法C";
    }
}


class Context{
    private $strategy;
    function __construct(Strategy $s){
        $this->strategy = $s;
    }
    function ContextInterface(){
        
        $this->strategy->AlgorithmInterface();
    }
}

$strategyA = new ConcreteStrategyA();
$context = new Context($strategyA);
$context->ContextInterface();

$strategyB = new ConcreteStrategyB();
$context = new Context($strategyB);
$context->ContextInterface();

$strategyC = new ConcreteStrategyC();
$context = new Context($strategyC);
$context->ContextInterface();

